package com.explorx.sns.puma.im.core.chat.consts;

import java.util.Arrays;
import java.util.Optional;

//
//  text,
//          image,
//          audio,
//          video,
//          file,
//          system,
//          custom,
public enum MessageTypeEnum {

    TEXT(0, "text"),
    IMAGE(1,"image"),
    AUDIO(2,"audio"),
    VIDEO(3,"video"),
    FILE(4,"file"),
    SYSTEM(5,"system"),
    CUSTOM(6,"custom"),

    UNKOWN(99, "未知消息类型");

    MessageTypeEnum(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    static public MessageTypeEnum findByValue(int value) {

        final Optional<MessageTypeEnum> any = Arrays.stream(MessageTypeEnum.values())
                .filter(ele -> ele.value == value).findAny();
        return any.isPresent() ? any.get() : UNKOWN;
    }

    static public MessageTypeEnum findByDesc(String desc) {
        final Optional<MessageTypeEnum> any = Arrays.stream(MessageTypeEnum.values())
                .filter(ele -> ele.getDesc().equals(desc)).findAny();
        return any.isPresent() ? any.get() : UNKOWN;
    }

    private int value;
    private String desc;

    public int getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
